// pages/new_inter/hotel_list/hotel_list.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: ['广东省', '广州市', '海珠区'],
    price_arr: [{
        id: 0,
        Title: '全部',
      },
      {
        id: 1,
        Title: '1万以下',
      },
      {
        id: 2,
        Title: '1万-1.5万',
      },
      {
        id: 3,
        Title: '1.5万-2万',
      },
      {
        id: 4,
        Title: '2万-2.5万',
      },
      {
        id: 5,
        Title: '2.5万以上',
      },

    ],
    //面积
    area_arr: [{
        id: 0,
        Title: '全部',
      },
      {
        id: 1,
        Title: '50㎡以下',
      },
      {
        id: 2,
        Title: '50㎡- 100㎡',
      },
      {
        id: 3,
        Title: '1.5万-2万',
      },
      {
        id: 4,
        Title: '100㎡- 150㎡',
      },
      {
        id: 5,
        Title: '200㎡以上',
      },

    ],

    num: '3',
    contZu: [{
      contZuImg: '../../images/6.jpg',
      contZuP: '五指山·雨林康养',
    }, {
      contZuImg: '../../images/6.jpg',
      contZuP: '五指山·雨林康养',
    }, {
      contZuImg: '../../images/6.jpg',
      contZuP: '五指山·雨林康养',
    }],
    fotZu: [{
        fotp0: '关于我们',
        fotp1: '了解蓝旗',
        fotp2: '招商加盟',
        fotp3: '商品发布',
        fotp4: '商家入驻'
      },
      {
        fotp0: '服务协议',
        fotp1: '用户服务协议',
        fotp2: '隐私权政策',
        fotp3: '预订服务条款',
        fotp4: ''
      },
      {
        fotp0: '蓝旗学院',
        fotp1: '微信营销',
        fotp2: '运营指导',
        fotp3: '只能拓客',
        fotp4: ''
      }
    ],
    fotewm: [{
        fotewm: '../../images/app_qrcode.png',
        title: '下载APP'
      },
      {
        fotewm: '../../images/wechat.jpg',
        title: '关注公众号'
      },
      {
        fotewm: '../../images/erweima.png',
        title: '小程序'
      }
    ],
    hostUrl: app.globalData.hostUrl,
    prov: '',
    city: '',
    county: '',
    type: '',
    apartment_type: '',
    price: '',
    area: '',
    // 三联属性
    array: ['省'],
    shiarray: ['市'],
    quarray: ['区'],
    index: 0,
    shiindex: 0,
    quindex: 0,
    clickShow: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      foot:wx.getStorageSync('foot'),
      is_show:wx.getStorageSync('is_show')

    })
    this.house_list();
  },
  house_list: function() {
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'House/lists',
      data: {
        prov: that.data.prov,
        city: that.data.city,
        county: that.data.county,
        type: that.data.type,
        apartment_type: that.data.apartment_type,
        price: that.data.price,
        area: that.data.area,

      },
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        // console.log(res)
        if (res.data != null) {

          // var adv = res.data.adv[0];
          // for (var i = 0, len = adv.length; i < 2; ++i) {
          //   var desc = that.delHtmlTag(res.data.adv[0][i].desc)
          //   res.data.adv[0][i].desc = desc;
          // }
          that.setData({
            info: res.data,
            array: res.data.province

          })
          console.log(that.data.info, '过滤后')
        }
      }
    })
  },
  //省市区选择
  bindRegionChange: function(e) {
    console.log(e)
    var that = this;
    var area = e.detail.code
    that.setData({
      area: area
    })
    that.house_list();
  },
  //配套设施
  bindpeitao_Change: function(e) {
    console.log(e)
    var that = this;
    var index = e.detail.value;
    var peitao = that.data.info['types'];
    that.setData({
      type: peitao[index]['id']
    })
    that.house_list();

    console.log(that.data.xuan_peitao, '选中条件')
  },
  //户型
  bindhuxing_Change: function(e) {
    var that = this;
    var index = e.detail.value;
    var apartment_type = that.data.info['apartment_types'];
    that.setData({
      apartment_type: apartment_type[index]['id']
    })
    that.house_list();
  },
  //单价
  bindprice_Change: function(e) {
    var that = this;
    var index = e.detail.value;
    var price_arr = that.data.price_arr;
    that.setData({
      price: area_arr[index]['id']
    })
    that.house_list();

  },
  //面积
  bindarea_Change: function(e) {
    var that = this;
    var index = e.detail.value;
    var area_arr = that.data.area_arr;
    that.setData({
      area: area_arr[index]['id'],
      clickShow: false
    })
    that.house_list();
  },
  // 三联开始
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为省', e.detail.value)
    var code = this.data.array[e.detail.value]['AreaId'];
    var index = e.detail.value;
    if (this.data.info['province'][index]['AreaName'] == "请选择") {
      return;
    }
    this.setData({
      index: e.detail.value,
      prov: code
    })
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Hotel/getarea',
      data: {
        ParentId: that.data.info['province'][index]['AreaId'],
        type: 'house'
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        // console.log(res)
        if (res.data != null) {
          that.setData({
            shiarray: res.data,
          })
        }
      }
    })
    that.house_list();
  },
  bindShiChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var code = this.data.shiarray[e.detail.value]['AreaId'];
    var shiindex = e.detail.value;
    if (this.data.shiarray[shiindex]['AreaName'] == "请选择") {
      return;
    }
    this.setData({
      shiindex: e.detail.value,
      city: code
    })
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Hotel/getarea',
      data: {
        ParentId: that.data.shiarray[shiindex]['AreaId'],
        type: 'house'
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        // console.log(res)
        if (res.data != null) {
          that.setData({
            quarray: res.data,
          })
        }
      }
    })
    that.house_list();

  },
  bindQuChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var code = this.data.quarray[e.detail.value]['AreaId'];
    if (this.data.quarray[e.detail.value]['AreaName'] == "请选择") {
      return;
    }
    this.setData({
      quindex: e.detail.value,
      qucode: code
    })
    this.house_list();
  },

  // 点击显示三联
  clickCityPicker: function() {
    this.setData({
      clickShow: true
    })
  },
  clickCityPickerhide:function(){
    this.setData({
      clickShow: false
    })
  },
  // 三联结束

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  //onShareAppMessage: function () {

  //},
  index: function() {
    wx.reLaunch({
      url: '/pages/index/index'
    })
  },
})